$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/yhbUser/list',
        datatype: "json",
        colModel: [
            {label: '账号', name: 'userId', index: "user_id", width: 85, key: true,align:"center"},
            {label: '账号', name: 'userNo',  width: 45, key: true,align:"center"},
            {label: '用户名', name: 'username', width: 75,align:"center"},
            {label: '手机号', name: 'phone', sortable: false, width: 75,align:"center"},
            {label: '身份证号码', name: 'identity', width: 60,formatter:function (value,options,row) {
                    return value==null? "暂无身份证号":value;
                },align:"center"},
            {label: '注册时间', name: 'createDate', width: 85,align:"center"},
            {label: '全部交易', name: 'totalTrade',  width: 85,formatter:function (value,options,row) {
                    return value.toFixed(2);
                },align:"center"},
            {label: '总分润', name: 'totalAmount',  width: 85,formatter:function (value,options,row) {
                    return value.toFixed(2);
                },align:"center"},
            {label: '可提余额', name: 'availableAmount', width: 90,formatter:function (value,options,row) {
                    return value.toFixed(2);
                },align:"center"},
            {label: '冻结金额', name: 'freezenAmount', width: 85,formatter:function (value,options,row) {
                    return value.toFixed(2);
                },align:"center"}

        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});
var exmiane;

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            username: null,
            phone: null

        },
        showList: true,
        title: null,
        roleList: {},
        user: {
            status: 1,
            deptId: null,
            deptName: null,
            roleIdList: []
        },

    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";

        },

        update: function () {
            var userId = getSelectedRow();
            if (userId == null) {
                return;
            }

            vm.showList = false;
            vm.title = "修改";

        },
        del: function () {
            var userIds = getSelectedRows();
            if (userIds == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/user/delete",
                    contentType: "application/json",
                    data: JSON.stringify(userIds),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function () {
                                vm.reload();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },

        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'username': vm.q.username,'phone':vm.q.phone},
                page: page
            }).trigger("reloadGrid");
        }

    }
});